#!/usr/bin/php
<?php

const NUM0 = 48;
const NUM9 = 57;

function main()
{
    // printf("请输入字符串: ");
    // $s = fgets(STDIN);
    $s = "sdf123sdfkj456sfjd12";

    $l = strlen($s);

    for ($i = 0, $sum = 0, $n = ""; $i < $l; ++$i) {
        $ch = ord($s[$i]);
        if ($ch >= NUM0 && $ch <= NUM9)
            $n .= $s[$i];
        else if ($n != "")
        {
            $sum += $n;
            $n = "";
        }
    }

    if ($n != "")
        $sum += $n;

    echo "sum = ", $sum, PHP_EOL;

    return 0;
}

exit(main());

